﻿using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace FirebirdDAO
{
    ///<summary>
    /// DAO Class for the Project table.
    ///</summary>
    public class Project : Entity
    {
        private String _PROJ_ID;
        private String _PROJ_NAME;
        private Byte[] _PROJ_DESC;
        private Int16 _TEAM_LEADER;
        private String _PRODUCT;

        ///Default constructor
        public Project()
        {

        }

        /// <summary>
        /// Constructor for joins. 
        /// Available CHILD tables to join with:
        ///    - Employee_project ( Employee_project_integ_41 )
        ///    - Proj_dept_budget ( Proj_dept_budget_integ_48 )
        /// Available PARENT tables to join with:
        ///    - Employee
        /// </summary>
        public Project(bool Flat, params Entity[] entities)
            : this()
        {
            foreach (Entity entity in entities)
            {
                string[] entityParts = entity.GetType().ToString().Split('.');
                string entityName = entityParts[entityParts.Length - 1];
                PropertyInfo pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, new EntityCollection(entity), null);
                }
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
            }
            SetFlat(Flat);
        }

        ///Constructor for Joins with flat hierarchy
        public Project(params Entity[] entities)
            : this(true, entities)
        {
        }

        ///<summary>
        /// Property for column Proj_id.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        [MaxLength(5)]
        public String Proj_id
        {
            get
            {
                return _PROJ_ID;
            }
            set
            {
                _PROJ_ID = value;
            }
        }
        ///<summary>
        /// Property for column Proj_name.
        ///</summary>
        [IsNotNullable]
        [MaxLength(20)]
        public String Proj_name
        {
            get
            {
                return _PROJ_NAME;
            }
            set
            {
                _PROJ_NAME = value;
            }
        }
        ///<summary>
        /// Property for column Proj_desc.
        ///</summary>
        public Byte[] Proj_desc
        {
            get
            {
                return _PROJ_DESC;
            }
            set
            {
                _PROJ_DESC = value;
            }
        }
        ///<summary>
        /// Property for column Team_leader.
        ///</summary>
        public Int16 Team_leader
        {
            get
            {
                return _TEAM_LEADER;
            }
            set
            {
                _TEAM_LEADER = value;
            }
        }
        ///<summary>
        /// Property for column Product.
        ///</summary>
        [MaxLength(12)]
        public String Product
        {
            get
            {
                return _PRODUCT;
            }
            set
            {
                _PRODUCT = value;
            }
        }

        #region Employee_project
        private EntityCollection _Employee_project;
        ///<summary>
        /// Related table Employee_project as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Employee_project), "Employee_project")]
        public EntityCollection Employee_project
        {
            get
            {
                return _Employee_project;
            }

            set
            {
                _Employee_project = value;
            }
        }
        private Employee_project _Employee_project_;
        ///<summary>
        /// Related table Employee_project as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Employee_project Employee_project_
        {
            get
            {
                return _Employee_project_;
            }

            set
            {
                _Employee_project_ = value;
            }
        }
        #endregion

        #region Proj_dept_budget
        private EntityCollection _Proj_dept_budget;
        ///<summary>
        /// Related table Proj_dept_budget as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Proj_dept_budget), "Proj_dept_budget")]
        public EntityCollection Proj_dept_budget
        {
            get
            {
                return _Proj_dept_budget;
            }

            set
            {
                _Proj_dept_budget = value;
            }
        }
        private Proj_dept_budget _Proj_dept_budget_;
        ///<summary>
        /// Related table Proj_dept_budget as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Proj_dept_budget Proj_dept_budget_
        {
            get
            {
                return _Proj_dept_budget_;
            }

            set
            {
                _Proj_dept_budget_ = value;
            }
        }
        #endregion
        #region Employee
        private EntityCollection _Employee;
        ///<summary>
        /// Related table Employee as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Employee), "Employee")]
        public EntityCollection Employee
        {
            get
            {
                return _Employee;
            }

            set
            {
                _Employee = value;
            }
        }
        private Employee _Employee_;
        ///<summary>
        /// Related table Employee as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Employee Employee_
        {
            get
            {
                return _Employee_;
            }

            set
            {
                _Employee_ = value;
            }
        }
        #endregion
        /// <summary>
        /// Gets join for current entity and table.
        /// </summary>
        /// <param name="tableName">Table to join with entity.</param>
        /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
            if (string.Compare(tableName, "Employee_project", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Proj_id");
                right.Add(GetType().Name + ".Proj_id");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Proj_dept_budget", StringComparison.OrdinalIgnoreCase) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Proj_id");
                right.Add(GetType().Name + ".Proj_id");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            if (string.Compare(tableName, "Employee", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Emp_no");
                right.Add(GetType().Name + ".Team_leader");
                return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
            }
            return null;
        }
    }
}


